package control;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.TimerTask;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;

public class MyMonitorTask extends TimerTask{
	static int NO=0;
	ControlClient client;
	FileWriter in;
	String fileName="a";
	int no;
	public MyMonitorTask(ControlClient controlClient,String fileName) throws IOException {
		this.client=controlClient;
		this.fileName=fileName;
		File file=new File("logs/"+fileName);
		in=new FileWriter(file, true);
		no=NO++;
	}
	@Override
	public void run() {
		try {
			in.write(new Date()+"\t:\t"+client.getRates());
			in.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MalformedObjectNameException e) {
			e.printStackTrace();
		} catch (AttributeNotFoundException e) {
			e.printStackTrace();
		} catch (InstanceNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NullPointerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MBeanException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ReflectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void close(){
		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
